package com.huawei.statistics.config;

import com.huawei.statistics.common.service.kdbird.KDBird;
import com.huawei.statistics.common.service.wx.WXPlatform;
import com.huawei.statistics.exception.GlobalException;
import com.huawei.statistics.platform.monitor.ClientManager;
import com.huawei.statistics.schedule.factory.MyJobFactory;
import com.huawei.statistics.schedule.job.MyQuartzJobBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * Created by op on 2017/11/4.
 */
@Configuration
@PropertySource(ignoreResourceNotFound = true, value = {"classpath:sysConfig.properties"})
public class CommonConfig {

    @Bean
    public ClientManager getClientManager(){
        ClientManager clientManager=new ClientManager();
        return clientManager;
    }

    @Bean
    public GlobalException getGloableException(){
        GlobalException globalException=new GlobalException();
        return globalException;
    }


    @Bean
    public WXPlatform getWXPlatform(@Value("${wx_pay_secret}")String paySecret,
                                    @Value("${wx_mch_id}")String mchId,
                                    @Value("${wx_appid}")String publicAppid,
                                    @Value("${wx_appsecret}")String publicSecret){
        WXPlatform wxPlatform=new WXPlatform();
        wxPlatform.setPaySecret(paySecret);
        wxPlatform.setPayMchid(mchId);
        wxPlatform.setPublicAppid(publicAppid);
        wxPlatform.setPublicSecret(publicSecret);
        return wxPlatform;
    }

    @Bean
    public KDBird getKdBird(@Value("${kd_bird_eBusinessID}")Integer businessID, @Value("${kd_bird_appkey}")String appKey){
        KDBird kdBird=new KDBird();
        kdBird.seteBusinessID(businessID);
        kdBird.setAppKey(appKey);
        return kdBird;
    }
    
    @Bean
    public MyJobFactory jobFactory(){
    	return new MyJobFactory();
    }
    
    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(){
    	SchedulerFactoryBean schedulerFactoryBean=new SchedulerFactoryBean();
    	schedulerFactoryBean.setApplicationContextSchedulerContextKey("applicationContextKey");
    	schedulerFactoryBean.setJobFactory(jobFactory());
    	return schedulerFactoryBean;
    }
    
    @Bean
    public JobDetailFactoryBean jobDetailFactoryBean(){
    	JobDetailFactoryBean jobDetailFactoryBean=new JobDetailFactoryBean();
    	jobDetailFactoryBean.setJobClass(MyQuartzJobBean.class);
    	jobDetailFactoryBean.setDurability(true);
    	return jobDetailFactoryBean;
    }
    
    
    
    
    

}
